package com.wondedDream.jwt;

import com.wondedDream.model.CustomUserDetails;
import com.wondedDream.repository.UserRepository;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

@Service
public class MyUserDetailsService  implements UserDetailsService {

    private final UserRepository userRepository; // 假设这是一个JPA Repository

    public MyUserDetailsService(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @Override
    public UserDetails loadUserByUsername(String openId) throws UsernameNotFoundException {
        com.wondedDream.model.User userEntity = userRepository.findByOpenid(openId);
        return new CustomUserDetails(userEntity);
    }
}
